/**
 * @(#)OrderCartCoreServiceImpl.java, 2018/2/12.
 * <p/>
 * Copyright 2018 Kerr Wang, Inc. All rights reserved.
 * KERRWANG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.service.core.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wangzx.exercise.dao.OrderCartDao;
import org.wangzx.exercise.enums.BuyStateType;
import org.wangzx.exercise.meta.bean.OrderCartBean;
import org.wangzx.exercise.meta.convertor.CommonConvertor;
import org.wangzx.exercise.meta.po.OrderCart;
import org.wangzx.exercise.service.core.OrderCartCoreService;

import java.util.List;

/**
 * @author hzwangzuxiang(ahscwzx@163.com)
 */
@Service("orderCartCoreService")
public class OrderCartCoreServiceImpl implements OrderCartCoreService {
    static private final Logger logger = LoggerFactory.getLogger(OrderCartCoreServiceImpl.class);

    @Autowired
    private OrderCartDao orderCartDao;

    @Override
    public List<OrderCartBean> getByBuyerAndState(long buyerId, BuyStateType buyStateType) {
        return CommonConvertor.poToBo(orderCartDao.getByBuyAndState(buyerId, buyStateType), OrderCartBean.class);
    }

    @Override
    public OrderCartBean getByBuyerAndItemId(long buyerId, long itemId) {
        return CommonConvertor.poToBo(orderCartDao.getByBuyAndItemId(buyerId, itemId), OrderCartBean.class);
    }

    @Override
    public OrderCartBean getById(long id) {
        return CommonConvertor.poToBo(orderCartDao.getById(id), OrderCartBean.class);
    }

    @Override
    public boolean updateOrderCart(OrderCartBean bean) {
        return orderCartDao.updateOrderCart(CommonConvertor.boToPo(bean, OrderCart.class));
    }

    @Override
    public long insert(OrderCartBean bean) {
        bean.setCreateTime(System.currentTimeMillis());
        bean.setUpdateTime(System.currentTimeMillis());
        return orderCartDao.insert(CommonConvertor.boToPo(bean, OrderCart.class));
    }
}
